<?php

namespace app\services;

use app\payment\PayFactory;
use plugin\admin\app\common\Util;
use plugin\admin\app\model\Payment;
use plugin\admin\app\model\User;

class PaymentService
{
    public static function list()
    {
        $list = Payment::where('is_enable', 1)->orderBy('sort')->get()->toArray();

        foreach ($list as $key=>$item) {
            $item['logo'] = full_url($item['logo']);
            $list[$key] = $item;
        }

        return $list;
    }

    public static function checkPayPassword($password)
    {
        $userInfo = User::where('id', get_user_id())->first();

        if (!$userInfo['pay_password']) {
            throw new \Exception('请先设置支付密码');
        }

        if (!$password) {
            throw new \Exception('支付密码不能为空');
        }

        if (! Util::passwordVerify($password, $userInfo['pay_password'])) {
            throw new \Exception('支付密码不正确');
        }
    }

    public static function needCheckPaymentPassword($payWay)
    {
        return false;
        return $payWay != PayFactory::WECHAT && $payWay != PayFactory::ALIPAY;
    }

    public static function dontNeedCallback($payWay)
    {
        return $payWay != PayFactory::WECHAT && $payWay != PayFactory::ALIPAY;
    }
}